<template>
	<view class="my-settle-container">

		<label class="radio">
			<radio @click="exchangeState" :checked="isFullchecked()" :color="'red'" /><text>全选</text>
		</label>
		<view class="amount-box">
			合计:<text class="amount">{{allCheckedPriceTotal}}￥</text>
		</view>
		<view @click="settlement" class="button-settle">结算({{checkedCount}})</view>
	</view>
</template>
<script>
	import {
		mapGetters,
		mapMutations,
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				seconds: 3,
				timer: null
			};
		},
		computed: {
			...mapState('cart', ['cartList']),
			...mapState('user',['token']),
			...mapGetters('cart', ['checkedCount', 'total', 'allCheckedPriceTotal']),
			...mapGetters('user', ['address','getAddress'])
		},
		methods: {
			...mapMutations('user',['updateRedirectInfo']),
			shopTips(n) {
				uni.showToast({
					title: '请登录后再结算 ' + n + '秒后自动跳转到登录页面',
					icon: 'none',
					mask: true,
					duration: 1500
				})
			},
			settlement() {
				if (!this.checkedCount) {
					uni.$showMsg('请选择要结算的商品', 1500)
					return
				}
				if (!this.getAddress) {
					console.log(this.getAddress || '地址为空')
					uni.$showMsg('请选择收货地址', 1500)
					return
				}
				if (!this.token) {
					this.delayNavigator()
					return
				}
			},
			delayNavigator() {
				
				this.shopTips(this.seconds)
				this.timer =  setInterval(() => {
					
					this.seconds--
					if(this.seconds <=0){
						clearInterval(this.timer)
						const that = this
						uni.switchTab({
							url:'/pages/my/my',
							success() {
								that.updateRedirectInfo({
									openType : 'switchTab',
									from: '/pages/cart/cart'
								})
								
							}
						})
						this.seconds = 3
						return
					}
					
						this.shopTips(this.seconds)
				}, 1000)
			},
			exchangeState() {
				this.updateAllState(!this.isFullchecked())
			},
			...mapMutations('cart', ['updateAllState']),
			isFullchecked() {
				if (this.total === this.checkedCount) {
					return true
				} else {
					return false
				}
			},
		}
	}
</script>
<style lang="scss">
	.my-settle-container {
		z-index: 999;
		height: 50px;
		width: 100%;
		position: fixed;
		bottom: 0;
		left: 0;
		background-color: white;
		display: flex;
		justify-content: space-between;
		align-items: center;
		font-size: 15px;
		padding-left: 5px;

		.radio {
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.amount-box {
			.amount {
				color: red;
				font-weight: bold;
				font-size: 16px;
			}

		}

		.button-settle {

			background-color: red;
			height: 100%;
			color: white;
			line-height: 50px;
			text-align: center;
			min-width: 100px;
		}
	}
</style>